package Servelts;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import daoFactory.DaoFactory;
import vo.Good;
import vo.Order;
import vo.User;

@WebServlet("/jump")
public class IndexServlet extends HttpServlet {
 
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String status = request.getParameter("status");
		String url = "error.jsp";
		//底部跳转
		if(status.equals("foot")){
			url  = "footer.jsp";
		}
		//头部跳转
		if(status.equals("top")){
			url = "top.jsp";
		}
		//购物主页跳转
		if(status.equals("shopindex")){
			url = "shopShow.jsp";
		}
		//充值界面跳转
		if(status.equals("recharge")){
			List<User> users = DaoFactory.getUserFactory().list();
			request.setAttribute("users", users);
			url = "rechargeEnter.jsp";
		}
		
		//首页跳转
		if(status.equals("index")){
			request.getSession().setAttribute("page", "front");
			List<Good> products = DaoFactory.getGoodFactory().list();
			request.setAttribute("products", products);
			url = "content.jsp";
		}
		//后台跳转
		if(status.equals("backpage")){
			if(request.getSession().getAttribute("role").equals("1")){
				request.getSession().setAttribute("page", "back");
				response.sendRedirect("index.jsp");
				return;
			}
			url = "jump?status=shopindex";
		}
		
		if(status.equals("addmoney")){
			User user = DaoFactory.getUserFactory().get(request.getParameter("uid"));
			request.setAttribute("user", user);
			url = "addMoney.jsp";
			
		}
		//用户充值入口
		if(status.equals("myrecharge")){
			User user = DaoFactory.getUserFactory().get(request.getParameter("uid"));
			request.setAttribute("user", user);
			url = "myrecharge.jsp";
		}

		//返回到商品表
		if(status.equals("listproduct")){
			request.getSession().setAttribute("page", "back");
			url = "listProduct?status=selectall";
		}
		
		if(status.equals("shopProduct")){
			request.getSession().setAttribute("page", "front");
			url = "listProduct?status=selectall";
		}
		//首页个人信息跳转
		if(status.equals("myinfo")){
			User user = DaoFactory.getUserFactory().get((String)request.getSession().getAttribute("userid"));
			request.setAttribute("user", user);
			List<Order> orderlist = DaoFactory.getOrderFactory().list(user.getUid());
			request.setAttribute("myorder", orderlist);
			url = "myinfo.jsp";
		}
		
		if(status.equals("uinfochange")){
			User user = DaoFactory.getUserFactory().get((String)request.getSession().getAttribute("userid"));
			request.setAttribute("user", user);
			url = "myinfocharge.jsp";
		}
		
		
		request.getRequestDispatcher(url).forward(request, response);
	}
	

}
